package com.erci.controller.admin;

import com.erci.entity.Category;
import com.erci.result.PageResult;
import com.erci.result.Result;
import com.erci.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "http://localhost:5173")
@RestController
@RequestMapping("/admin/api/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //查询
    @GetMapping("/list")
    public Result<PageResult> queryList(Integer page, Integer pageSize, String name) {
        PageResult pageResult = categoryService.queryList(page,pageSize, name);
        return Result.success(pageResult);
    }
    //添加
    @PostMapping("/add")
    public Result<String> add(@RequestBody Category category) {
        categoryService.add(category);
        return Result.success("添加成功");
    }
    //更新
    @PostMapping("/update")
    public Result<String> update(@RequestBody Category category) {
        categoryService.update(category);
        return Result.success("更新成功");
    }
//
    //删除
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody Category category) {
        categoryService.delete(category);
        return Result.success("删除成功");
    }
}
